package etxt2db.features;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;



public class SubstringFeatureClassifier extends CharacterFeatureClassifier implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -86833610860537045L;
	int begin;
	int end;
	
	public SubstringFeatureClassifier(int begin, int end){
		this.begin = begin;
		this.end = end;
	}
	
	@Override
	public List<String> emit(String text) {
		int convertedBegin;
		int convertedEnd;
		if(begin>=0 && end>=begin){
			convertedBegin=Math.min(begin,text.length()-1);
			convertedEnd=Math.min(text.length()-convertedBegin,end);
		}else if(begin<0 && end<=0 &&  begin<=end){
			convertedBegin=Math.max(text.length()+begin,0);
			convertedEnd=Math.max(text.length()+end,0);
		}else{
			throw new IllegalArgumentException("illegal subString indices "+begin+", "+
					end);
		}
		List<String> result = new ArrayList<String>();
		result.add("subString_" + begin + "_" + end + "=" + text.substring(convertedBegin,convertedEnd));
		return result;
	}

}
